//
// Copyright (c) 2009-2011, chunquedong
//
// This file is part of ChunMap project
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE(Version >=3)
//
// History:
//   2011-09-30  Jed Young  Creation
//

using gfx
using gfx2

using chunmapModel
using chunmapData
using chunmapRaster

**
** simple draw polygon
**
@Js
const class SimplePolygonSym : GeometrySym
{
  const Pen pen := Pen.defVal
  const Brush brush := Color.green
  const Brush strokeBrush := Color.black

  const Bool fill := true
  const Bool stroke := true

  new make(|This| f) { f(this) }

  override Void drawGeometry(Geometry geom, RenderEnv r)
  {
    if (geom isnot Polygon) return
    Polygon pg := geom

    g := r.g

    ls := pg.shell
    //TODO as result of holes, will change to path

    ps := DrawHelper.toIntArray(ls, r)
    if (fill)
    {
      if (g.brush != brush) g.brush = brush
      g.fillPolygon2(ps)
    }

    if (stroke)
    {
      if (g.brush != strokeBrush) g.brush = strokeBrush
      if (g.pen != pen) g.pen = pen
      g.drawPolyline2(ps)
    }
  }
}

